var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		options: [],
		datalist:[],
		pagenum: 1,
	},
	_onLoad: function () {
		var that = this
		this.getDataList()
	},
	getDataList: function(){
		var that = this
		var pagenum = that.data.pagenum
		var cid = that.options && that.options.cid ? that.options.cid : 0;
		if (that.options && that.options.scene) {
			var scene = that.options.scene
			var scenes = scene.split('_');
			if(scenes[1]=='cid'){
				cid = parseInt(scenes[2]);
			}
		}
		$.post('article/artlist', {cid:cid,pagenum:pagenum}, function (res) {
			var data = res.data
			if(pagenum == 1){
				that.setData({ datalist: data });
				if (data.length == 0){
					$.showEmpty('暂无记录','/images/empty2.png');
				}
			}else{
				if (data.length == 0){
					that.setData({$nomoreData:true});
				}else{
					var datalist = that.data.datalist
					var newdata = datalist.concat(data)
					that.setData({ datalist: newdata });
				}
			}
			wx.setNavigationBarTitle({ title: res.title})
		});
	},
	onReachBottom: function () {
		if (!this.data.$dataEmpty.visible && !this.data.$nomoreData){
			this.setData({ pagenum: this.data.pagenum+1 })
			this.getDataList();
		}
	},
}));